#! /bin/bash

DATAX_HOME=/opt/module/datax

#DataX导出路径不允许存在空文件，该函数作用为清理空文件
handle_export_path(){
  for i in `hadoop fs -ls -R $1 | awk '{print $8}'`; do
    hadoop fs -test -z $i
    if [[ $? -eq 0 ]]; then
      echo "$i文件大小为0，正在删除"
      hadoop fs -rm -r -f $i
    fi
  done
}

#数据导出
export_data() {
  datax_config=$1
  export_dir=$2
  handle_export_path $export_dir
  $DATAX_HOME/bin/datax.py -p"-Dexportdir=$export_dir" $datax_config
}

case $1 in
  "all")
    export_data /opt/module/datax/job/export/edu_report.ads_traffic_stats_by_source.json /warehouse/edu/ads/ads_traffic_stats_by_source
    export_data /opt/module/datax/job/export/edu_report.ads_page_path.json /warehouse/edu/ads/ads_page_path
    export_data /opt/module/datax/job/export/edu_report.ads_source_ordersum.json /warehouse/edu/ads/ads_source_ordersum
    export_data /opt/module/datax/job/export/edu_report.ads_user_change.json /warehouse/edu/ads/ads_user_change
    export_data /opt/module/datax/job/export/edu_report.ads_user_retention.json /warehouse/edu/ads/ads_user_retention
    export_data /opt/module/datax/job/export/edu_report.ads_user_stats.json /warehouse/edu/ads/ads_user_stats
    export_data /opt/module/datax/job/export/edu_report.ads_user_action.json /warehouse/edu/ads/ads_user_action 
    export_data /opt/module/datax/job/export/edu_report.ads_new_buyer_stats.json /warehouse/edu/ads/ads_new_buyer_stats
    export_data /opt/module/datax/job/export/edu_report.ads_age_order.json /warehouse/edu/ads/ads_age_order
    export_data /opt/module/datax/job/export/edu_report.ads_category_order.json /warehouse/edu/ads/ads_category_order
    export_data /opt/module/datax/job/export/edu_report.ads_subject_order.json /warehouse/edu/ads/ads_subject_order
    export_data /opt/module/datax/job/export/edu_report.ads_course_order.json /warehouse/edu/ads/ads_course_order
    export_data /opt/module/datax/job/export/edu_report.ads_process_user_review_by_course.json /warehouse/edu/ads/ads_process_user_review_by_course 
    export_data /opt/module/datax/job/export/edu_report.ads_category_retention.json /warehouse/edu/ads/ads_category_retention
    export_data /opt/module/datax/job/export/edu_report.ads_subject_retention.json /warehouse/edu/ads/ads_subject_retention
    export_data /opt/module/datax/job/export/edu_report.ads_course_retention.json /warehouse/edu/ads/ads_course_retention
    export_data /opt/module/datax/job/export/edu_report.ads_order_all.json /warehouse/edu/ads/ads_order_all
    export_data /opt/module/datax/job/export/edu_report.ads_order_by_province.json /warehouse/edu/ads/ads_order_by_province
    export_data /opt/module/datax/job/export/edu_report.ads_exam_avg.json /warehouse/edu/ads/ads_exam_avg
    export_data /opt/module/datax/job/export/edu_report.ads_exam_course_avg.json /warehouse/edu/ads/ads_exam_course_avg
    export_data /opt/module/datax/job/export/edu_report.ads_exam_score_distribution.json /warehouse/edu/ads/ads_exam_score_distribution
    export_data /opt/module/datax/job/export/edu_report.ads_exam_question_sum.json /warehouse/edu/ads/ads_exam_question_sum
    export_data /opt/module/datax/job/export/edu_report.ads_chapter_video_play.json /warehouse/edu/ads/ads_chapter_video_play
    export_data /opt/module/datax/job/export/edu_report.ads_course_video_play.json /warehouse/edu/ads/ads_course_video_play
    export_data /opt/module/datax/job/export/edu_report.ads_course_completed.json /warehouse/edu/ads/ads_course_completed
    export_data /opt/module/datax/job/export/edu_report.ads_all_completed.json /warehouse/edu/ads/ads_all_completed
    export_data /opt/module/datax/job/export/edu_report.ads_course_completed_person_avg.json /warehouse/edu/ads/ads_course_completed_person_avg
	:
  ;;
esac
